/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scacp;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.TitledBorder;

/**
 *
 * @author Cleber
 */
public class ProvaPainelDados extends javax.swing.JPanel {
    Prova prova;
    JFrame janelaPrincipal;
    /**
     * Creates new form ProvaPainelDados
     */
    public ProvaPainelDados(Prova prova, JFrame janelaPrincipal) {
        this.prova = prova;
        this.janelaPrincipal = janelaPrincipal;
        initComponents();
        preencherPainel(prova);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblQntQuestoesD = new javax.swing.JLabel();
        lblTipoProvaD = new javax.swing.JLabel();
        btnAlterar = new javax.swing.JButton();
        lblIncidenciaPenalizacao = new javax.swing.JLabel();
        lblProporcao = new javax.swing.JLabel();
        lblPrecicaoPontuacao = new javax.swing.JLabel();
        lblTipoProva = new javax.swing.JLabel();
        lblPontuacaoMinima = new javax.swing.JLabel();
        lblQntQuestoes = new javax.swing.JLabel();
        lblPrecicaoPontuacaoD = new javax.swing.JLabel();
        lblProporcaoD = new javax.swing.JLabel();
        lblPontuacaoMaxima = new javax.swing.JLabel();
        lblPontuacaoMinimaD = new javax.swing.JLabel();
        lblPontuacaoMaximaD = new javax.swing.JLabel();
        lblIncidenciaPenalizacaoD = new javax.swing.JLabel();
        btnConcluir = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Prova: ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Cantarell", 1, 14))); // NOI18N
        setMinimumSize(new java.awt.Dimension(441, 114));
        setName("painelDadosProva"); // NOI18N

        lblQntQuestoesD.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        lblQntQuestoesD.setText("MISC");
        lblQntQuestoesD.setName("qntQuestoes"); // NOI18N

        lblTipoProvaD.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        lblTipoProvaD.setText("MISC");
        lblTipoProvaD.setName("tipoProva"); // NOI18N

        btnAlterar.setText("Alterar");
        btnAlterar.setVisible(false);
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        lblIncidenciaPenalizacao.setText("Incidência de Penalização? ");

        lblProporcao.setText("Proporção: ");
        lblProporcao.setName("proporcaoPenalizacaoLabel"); // NOI18N

        lblPrecicaoPontuacao.setText("Precisão da Pontuação:");

        lblTipoProva.setText("Tipode de Prova:");

        lblPontuacaoMinima.setText("Pontuação Mínima:");

        lblQntQuestoes.setText("Quantidade de Questões:");

        lblPrecicaoPontuacaoD.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        lblPrecicaoPontuacaoD.setText("3");
        lblPrecicaoPontuacaoD.setName("precisaoPontuacao"); // NOI18N

        lblProporcaoD.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        lblProporcaoD.setText("0");
        lblProporcaoD.setName("proporcaoPenalizacaoValor"); // NOI18N

        lblPontuacaoMaxima.setText("Pontuação Máxima:");

        lblPontuacaoMinimaD.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        lblPontuacaoMinimaD.setText("150");
        lblPontuacaoMinimaD.setName("pontuacaoMinima"); // NOI18N

        lblPontuacaoMaximaD.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        lblPontuacaoMaximaD.setText("150");
        lblPontuacaoMaximaD.setName("pontuacaoMaxima"); // NOI18N

        lblIncidenciaPenalizacaoD.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        lblIncidenciaPenalizacaoD.setText("MISC");
        lblIncidenciaPenalizacaoD.setName("incidenciaPenalizacaoBoolean"); // NOI18N

        btnConcluir.setText("Concluir");
        btnConcluir.setVisible(false);
        btnConcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConcluirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(lblPontuacaoMinima)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblPontuacaoMinimaD))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(lblPontuacaoMaxima)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblPontuacaoMaximaD))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(lblPrecicaoPontuacao)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lblPrecicaoPontuacaoD)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblTipoProva)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTipoProvaD)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblProporcao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblProporcaoD)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAlterar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnConcluir))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblQntQuestoes)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblQntQuestoesD))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblIncidenciaPenalizacao)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblIncidenciaPenalizacaoD)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTipoProva)
                    .addComponent(lblQntQuestoes)
                    .addComponent(lblTipoProvaD)
                    .addComponent(lblQntQuestoesD))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPontuacaoMinima)
                    .addComponent(lblPontuacaoMinimaD)
                    .addComponent(lblIncidenciaPenalizacao)
                    .addComponent(lblIncidenciaPenalizacaoD))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblPontuacaoMaxima)
                            .addComponent(lblPontuacaoMaximaD)
                            .addComponent(lblProporcao)
                            .addComponent(lblProporcaoD))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblPrecicaoPontuacao)
                            .addComponent(lblPrecicaoPontuacaoD))
                        .addGap(12, 12, 12))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnAlterar)
                            .addComponent(btnConcluir))
                        .addContainerGap())))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        ProvaFormulario formularioProva = new ProvaFormulario(janelaPrincipal, true, prova);
        formularioProva.setTitle("Alterar Prova");
        formularioProva.setLocationRelativeTo(janelaPrincipal);
        formularioProva.setVisible(true);
        if(!prova.isProvaSalva()){
            preencherPainel(prova);
        }
    }//GEN-LAST:event_btnAlterarActionPerformed

    private void btnConcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConcluirActionPerformed
        btnAlterar.setVisible(false);
        btnConcluir.setVisible(false);
    }//GEN-LAST:event_btnConcluirActionPerformed

    public void preencherPainel(Prova prova){
        this.prova = prova;
        ((TitledBorder) getBorder()).setTitle("Prova: " + prova.getNome());
        lblTipoProvaD.setText(""+prova.getTipoProva());
        lblQntQuestoesD.setText(""+prova.getQuantidadeQuestoes());
        switch(prova.getPrecisaoPontuacao()){
            case 0:
                lblPontuacaoMinimaD.setText(String.format("%.0f", prova.getPontuacaoMinima()));
                lblPontuacaoMaximaD.setText(String.format("%.0f", prova.getPontuacaoMaxima()));
                break;
            case 1:
                lblPontuacaoMinimaD.setText(String.format("%.1f", prova.getPontuacaoMinima()));
                lblPontuacaoMaximaD.setText(String.format("%.1f", prova.getPontuacaoMaxima()));
                break;
            case 2:
                lblPontuacaoMinimaD.setText(String.format("%.2f", prova.getPontuacaoMinima()));
                lblPontuacaoMaximaD.setText(String.format("%.2f", prova.getPontuacaoMaxima()));
                break;
            case 3:
                lblPontuacaoMinimaD.setText(String.format("%.3f", prova.getPontuacaoMinima()));
                lblPontuacaoMaximaD.setText(String.format("%.3f", prova.getPontuacaoMaxima()));
                break;
        }
        lblPrecicaoPontuacaoD.setText(""+prova.getPrecisaoPontuacao());
        if(prova.getIncidenciaPenalizacao()){
            lblIncidenciaPenalizacaoD.setText("Sim");
            lblProporcao.setText("Proporção: ");
            lblProporcaoD.setText(""+prova.getProporcaoPenalizacao());
        }else{
            lblIncidenciaPenalizacaoD.setText("Não");
            lblProporcao.setText("");
            lblProporcaoD.setText("");
        }
        validate();
        repaint();
    }
    
    public Prova getProva() {
        return prova;
    }

    public void setProva(Prova prova) {
        this.prova = prova;
    }

    public JFrame getJanelaPrincipal() {
        return janelaPrincipal;
    }

    public void setJanelaPrincipal(JFrame janelaPrincipal) {
        this.janelaPrincipal = janelaPrincipal;
    }
    
    public void setNome(String nome){
        ((TitledBorder) getBorder()).setTitle("Prova: " + nome);
        repaint();
    }
    
    public void setIncidenciaPenalizacao(boolean incidenciaPenalizacao) {
        if(incidenciaPenalizacao){
            lblIncidenciaPenalizacaoD.setText("Sim");
            setProporcao("Proporção: ");
            setProporcaoPenalizacao(prova.getProporcaoPenalizacao());
        }else{
            lblIncidenciaPenalizacaoD.setText("Não");
            setProporcao("");
            lblProporcaoD.setText("");
        }
        repaint();
    }

    public void setPontuacaoMaxima(Double pontuacaoMaxima) {
        switch(prova.getPrecisaoPontuacao()){
            case 0:
                lblPontuacaoMaximaD.setText(String.format("%.0f", prova.getPontuacaoMaxima()));
                break;
            case 1:
                lblPontuacaoMaximaD.setText(String.format("%.1f", prova.getPontuacaoMaxima()));
                break;
            case 2:
                lblPontuacaoMaximaD.setText(String.format("%.2f", prova.getPontuacaoMaxima()));
                break;
            case 3:
                lblPontuacaoMaximaD.setText(String.format("%.3f", prova.getPontuacaoMaxima()));
                break;
        }
        repaint();
    }

    public void setPontuacaoMinima(Double pontuacaoMinima) {
        switch(prova.getPrecisaoPontuacao()){
            case 0:
                lblPontuacaoMinimaD.setText(String.format("%.0f", prova.getPontuacaoMinima()));
                break;
            case 1:
                lblPontuacaoMinimaD.setText(String.format("%.1f", prova.getPontuacaoMinima()));
                break;
            case 2:
                lblPontuacaoMinimaD.setText(String.format("%.2f", prova.getPontuacaoMinima()));
                break;
            case 3:
                lblPontuacaoMinimaD.setText(String.format("%.3f", prova.getPontuacaoMinima()));
                break;
        }
        repaint();
    }

    public void setPrecicaoPontuacao(int precicaoPontuacao) {
        lblPrecicaoPontuacaoD.setText("" + lblPrecicaoPontuacaoD);
        setPontuacaoMaxima(prova.getPontuacaoMaxima());
        setPontuacaoMinima(prova.getPontuacaoMinima());
        repaint();
    }

    private void setProporcao(String proporcao) {
        lblProporcao.setText(proporcao);
        repaint();
    }

    public void setProporcaoPenalizacao(int proporcaoPenalizacao) {
        lblProporcaoD.setText(""+proporcaoPenalizacao);
        repaint();
    }

    public void alterarQuantidadeQuestoes(int quantidadeQuestões){
        lblQntQuestoesD.setText("" + quantidadeQuestões);
        repaint();
    }

    public void setTipoProva(TipoProva tipoProva) {
        lblTipoProvaD.setText(tipoProva.getTipo());
        repaint();
    }
    
    
    
            
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnConcluir;
    private javax.swing.JLabel lblIncidenciaPenalizacao;
    private javax.swing.JLabel lblIncidenciaPenalizacaoD;
    private javax.swing.JLabel lblPontuacaoMaxima;
    private javax.swing.JLabel lblPontuacaoMaximaD;
    private javax.swing.JLabel lblPontuacaoMinima;
    private javax.swing.JLabel lblPontuacaoMinimaD;
    private javax.swing.JLabel lblPrecicaoPontuacao;
    private javax.swing.JLabel lblPrecicaoPontuacaoD;
    private javax.swing.JLabel lblProporcao;
    private javax.swing.JLabel lblProporcaoD;
    private javax.swing.JLabel lblQntQuestoes;
    private javax.swing.JLabel lblQntQuestoesD;
    private javax.swing.JLabel lblTipoProva;
    private javax.swing.JLabel lblTipoProvaD;
    // End of variables declaration//GEN-END:variables
}
